package com.example.study.testwaitandnotify;

/**
 * @author hjh
 * @create 2019-08-21 19:32
 **/
public class JmmTest implements Runnable {
    int a = 0;
    volatile  int b = 0;
    public void method1() {
        int r2 = a;
        b = 1;
        System.out.println("r2: " + r2);
    }
    public void method2() {
        int r1 = b;
        a = 2;
        System.out.println("r1: " + r1);
    }
    public static void main(String[] args) {
        JmmTest tmmTest = new JmmTest();
        Thread t1 = new Thread(tmmTest, "t1");
        Thread t2 = new Thread(tmmTest, "t2");
        t1.start();
        t2.start();
    }
    @Override
    public void run() {
        if ("t1".equals(Thread.currentThread().getName())) {
            method1();
        } else {
            method2();
        }
    }
}
